import axios from 'axios'
import store from "../store"
import { closeLoading, openLoading, toast } from "./common";

const httpRequest = axios.create({
  timeout: 600000,
  //baseURL: store.getters.ip
  //baseURL: 'http://10.156.8.224'
  //baseURL: 'http://47.107.187.189:81'
})
//响应器
httpRequest.interceptors.request.use(
  config => {
    config.baseURL = store.getters.ip;
    openLoading()
    return config
  },
  error => {
    toast(error.toString())
    return Promise.reject(error)
  }
)
//拦截器
httpRequest.interceptors.response.use(
  response => {
    closeLoading()
    if (response.data && response.data.status !== 200) {
      if (response.data.msg == '') {
        toast(response.data.msg)
      }
    }
    return response
  },
  error => {
    closeLoading()
    toast(error.toString());
    return error
  }
)

export default httpRequest
